home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1995 #5 & #6 / Amiga Plus CD - 1995 - No. 5 and 6.iso / pd / netz / term / extras / source / term-source.lha / termEmulationProcess.c < prev    next >
C/C++ Source or Header  |  1995-02-07  |  2KB  |  118 lines

  1. /*
  2. **    termEmulationProcess.c
  3. **
  4. **    Terminal emulation process
  5. **
  6. **    Copyright © 1990-1995 by Olaf `Olsen' Barthel
  7. **        All Rights Reserved
  8. */
  9.  
  10. #include "termGlobal.h"
  11.  
  12. STATIC struct Process *EmulationProcess;
  13.  
  14. STATIC VOID __saveds
  15. EmulationProcessEntry(VOID)
  16. {
  17.     if(TerminalQueue = CreateMsgQueue(NULL,40))
  18.     {
  19.         ULONG         Mask = SIG_KILL | TerminalQueue -> SigMask;
  20.         struct DataMsg    *Msg;
  21.         BOOLEAN         Done = FALSE;
  22.  
  23.         EmulationProcess = (struct Process *)FindTask(NULL);
  24.  
  25.         Signal(ThisProcess,SIG_HANDSHAKE);
  26.  
  27.         do
  28.         {
  29.             if(Wait(Mask) & SIG_KILL)
  30.                 break;
  31.  
  32.             ObtainSemaphore(&TerminalSemaphore);
  33.  
  34.             ClearCursor();
  35.  
  36.             while(Msg = GetMsgItem(TerminalQueue))
  37.             {
  38.                     /* Remember the data. */
  39.  
  40.                 if(RememberOutput)
  41.                     RememberOutputText(Msg -> Data,Msg -> Size);
  42.  
  43.                 (*ConProcessData)(Msg -> Data,Msg -> Size);
  44.  
  45.                 DeleteMsgItem(Msg);
  46.  
  47.                 if(SetSignal(0,0) & SIG_KILL)
  48.                 {
  49.                     Done = TRUE;
  50.  
  51.                     break;
  52.                 }
  53.             }
  54.  
  55.             DrawCursor();
  56.  
  57.             ReleaseSemaphore(&TerminalSemaphore);
  58.         }
  59.         while(!Done);
  60.  
  61.         DeleteMsgQueue(TerminalQueue);
  62.  
  63.         TerminalQueue = NULL;
  64.     }
  65.  
  66.     Forbid();
  67.  
  68.     EmulationProcess = NULL;
  69.  
  70.     Signal(ThisProcess,SIG_HANDSHAKE);
  71. }
  72.  
  73. VOID
  74. DeleteEmulationProcess()
  75. {
  76.     if(EmulationProcess)
  77.     {
  78.         Forbid();
  79.  
  80.         Signal(EmulationProcess,SIG_KILL);
  81.  
  82.         ClrSignal(SIG_HANDSHAKE);
  83.  
  84.         Wait(SIG_HANDSHAKE);
  85.  
  86.         Permit();
  87.     }
  88. }
  89.  
  90. BOOLEAN
  91. CreateEmulationProcess()
  92. {
  93.     if(!EmulationProcess)
  94.     {
  95.         Forbid();
  96.  
  97.         if(CreateNewProcTags(
  98.             NP_Name,    "term Emulation Process",
  99.             NP_Priority,    SysBase -> ThisTask -> tc_Node . ln_Pri,
  100.             NP_Entry,    EmulationProcessEntry,
  101.             NP_StackSize,    6000,
  102.             NP_WindowPtr,    Window,
  103.         TAG_DONE))
  104.         {
  105.             ClrSignal(SIG_HANDSHAKE);
  106.  
  107.             Wait(SIG_HANDSHAKE);
  108.         }
  109.  
  110.         Permit();
  111.     }
  112.  
  113.     if(EmulationProcess)
  114.         return(TRUE);
  115.     else
  116.         return(FALSE);
  117. }
  118.